package com.flower.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.flower.domain.dto.LoginDto;
import com.flower.domain.entity.Admin;
import com.flower.service.AdminService;
import com.flower.mapper.AdminMapper;
import com.flower.utils.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 86178
* @description 针对表【admin】的数据库操作Service实现
* @createDate 2025-02-17 20:54:03
*/
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin>
    implements AdminService{
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public Admin login(LoginDto loginDto) {
        // 根据用户名查询用户信息
        Admin admin = adminMapper.selectOne(new QueryWrapper<Admin>().eq("username", loginDto.getUsername()));
        // 判断用户是否存在
        if (admin != null) {
            // 判断密码是否正确
            if (Md5Util.checkPassword(loginDto.getPassword(),admin.getPassword())) {
                return admin;
            }
        }
        return null;
    }

    @Override
    public Admin findAdminByEmail(String email) {
        // 根据邮箱查询用户信息
        return adminMapper.selectOne(new QueryWrapper<Admin>().eq("email", email));
    }
}




